package com.deeper.customview.ui.c1.demo;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.deeper.customview.BaseFragment;
import com.deeper.customview.R;

public class Chapter01Demo05Fragment extends BaseFragment {
    private ImageView iv;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_chapter01_demo05, container, false);

        iv = root.findViewById(R.id.iv);

        Bitmap bmpBuffer = Bitmap.createBitmap(500, 800, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bmpBuffer);

        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(Color.GREEN);
        paint.setStrokeWidth(5);
        paint.setStyle(Paint.Style.FILL);
        Rect rect = new Rect(50, 50, 100, 100);
        canvas.drawRect(rect, paint);

        paint.setStyle(Paint.Style.STROKE);
        rect = new Rect(70, 70, 150, 200);
        canvas.drawRect(rect, paint);

        //圆角矩形
        RectF rectF = new RectF(100, 100, 200, 250);
        canvas.drawRoundRect(rectF, 10, 10, paint);


        iv.setImageBitmap(bmpBuffer);
        return root;
    }
}
